package com.zc.Interceptor;

import com.zc.Interceptor.UserInfoInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * 注册拦截器
 */
@Configuration
public class InterceptorConfigurer implements WebMvcConfigurer {

    @Bean
    public UserInfoInterceptor userInfoInterceptor(){
        return new UserInfoInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //这种方式会拦截所有请求
        //registry.addInterceptor(userInfoInterceptor());
        //这种方式会拦截指定的请求
        registry.addInterceptor(userInfoInterceptor()).addPathPatterns("/hello/gePojoTestLombok");
    }
}

